package douaPahare.operator;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

import douaPahare.container.Stare;


public class G1 extends JButton implements Operator {
	
    private JPanel panel;
	
	public G1(String nume,JPanel p) {
		super(nume);
		panel = p;
	}

	public void executa() throws Exception {
	    if(evaluare(Stare.getStareStatic()))
	    	Stare.setStareStatic(actiune(Stare.getStareStatic()));
		else throw new Exception("Nu se poate goli primul pahar!");
	}
	
	public boolean evaluare(Stare st) {
		if(st.getX() == 0) 
			return false;
		else return true;
	}
	
	public Stare actiune(Stare st) {
		final JProgressBar p = (JProgressBar)panel.getComponent(0);
		p.setValue(0);
		return new Stare(0,st.getY());
	}
	
	public Stare actiune2(Stare st) {
		return new Stare(0,st.getY());
	}

}
